//datosIniciales();


angular.module('odondata', []).
  config(['$routeProvider', function($routeProvider) {
  $routeProvider.
      when('/listaTemario', {templateUrl: 'pages/itemTemario.html',    controller: ListaTestCtrl}).
      when('/misConsultas', {templateUrl: 'pages/misConsultas.html',   controller: ListaTestCtrl}).
      when('/miCuenta',     {templateUrl: 'pages/miCuenta.html',       controller: MiCuentaCtrl}).
      when('/galeriaCasos', {templateUrl: 'pages/galeriaCasos.html',   controller: ListaTestCtrl}).
      when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: ListaTestCtrl}).
      otherwise({redirectTo: '/listaTemario'});
}]);


function ListaTestCtrl($scope) {
  /*$scope.botones = [
    {"label": "Nexus S",
     "snippet": "Fast just got faster with Nexus S.",
     'id':1},
    {"label": "Motorola XOOM with Wi-Fi",
     "snippet": "The Next, Next Generation tablet.",
     'id':2},
    {"label": "MOTOROLA XOOM",
     "snippet": "The Next, Next Generation tablet.",
     'id':3
     }
  ];*/
  $scope.botones = [];
  $scope.ttt = 'holaz';
  
  $scope.mostrarBoton = function(idBoton) {
  //alert (idBoton);
    /*var idBoton = null;*/
    if (idBoton == 2)
      return false;
    else
      return true;
  };
  
  $scope.prueba = function(data) {
        //alert (data);
        //alert ($scope.botones);
        //myArray = [];
         $scope.botones = [];
       // scope.botones.length = 0
        
        
        $.each(data, function(index, nodo) {
            $scope.botones.push(nodo);
        });
       
        
        $scope.$apply();
   // alert ($scope.botones);
  };
  
  
  $scope.navegarGaleria = function() {
        servicioData.getListaItems($scope.returnListaItems2);
  };
  
  $scope.llamarDWR = function() {
        servicioData.getListaItems($scope.returnListaItems2);
  };
  
  $scope.returnListaItems2 = function(data) {
        $scope.prueba(data);
  };
  
  $scope.borrar = function() {
      alert('borrar');
        //myArray = [];
          $scope.botones = [];
          
         // $scope.resize($scope.botones);
       // scope.botones.length = 0
       // $scope.botones.push(data);
        $scope.$apply();
   // alert ($scope.botones);
  };
  
  $scope.llamarDWR();
}

function llamar(){
  servicioData.holaMundo(handleGetData);
}

function datosIniciales(){
//alert('hola');
  //servicioData.getListaItems(returnListaItems);
 // servicioData.getListaItems(getListaTestCtrl().borrar);
  
  
}

function getListaTestCtrl(){
    return angular.element(document.getElementById('content')).scope()
}

function returnListaItems(data) {
    var e = document.getElementById('content');
    scope = angular.element(e).scope();
    // update the model with a wrap in $apply(fn) which will refresh the view for us
    //scope.$apply(function() {
        scope.borrar();
    //}); 

/*getListaTestCtrl().$apply(function() {
    getListaTestCtrl().borrar();
}); */
//getListaTestCtrl().$apply();
   // getListaTestCtrl().borrar();
   // getListaTestCtrl().$apply();
}

